<template>
  <promise-dialog ref="dialog">
    <form-alloc-role :userId="userId" @fatal='onFatal' @suc='onSubmit' />
  </promise-dialog>
</template>
<script lang="ts">
import Vue from 'vue'
import PromiseDialog from '@/components/PromiseDialog.vue'
import FormAllocRole from './FormAllocRole.vue'

export default Vue.extend({
  components: { PromiseDialog, FormAllocRole },
  name: 'DialogAllocRole',
  props: ['userId'],
  methods: {
    open () {
      return (this.$refs.dialog as PromiseDialog).open().catch(() => undefined)
    },
    onSubmit () {
      return (this.$refs.dialog as PromiseDialog).resolve()
    },
    onFatal (message: unknown) {
      return (this.$refs.dialog as PromiseDialog).reject(message)
    }
  }
})
</script>
